#include "Sound.h"
#include "game.h"
#pragma comment(lib, "audiere.lib")

int ADR_CALL Sound::read(void* buffer, int size)
{
	int sizeToRead = size;
	if((int)getDataSize() - filePtr < sizeToRead)
		sizeToRead = getDataSize() - filePtr;
	memcpy(buffer, (char*)getData() + filePtr, sizeToRead);
	filePtr += sizeToRead;
	return sizeToRead;
}

bool ADR_CALL Sound::seek(int position, audiere::File::SeekMode mode)
{
	switch(mode)
	{
	case BEGIN:
		filePtr = position;
		break;
	case CURRENT:
		filePtr += position;
		break;
	case END:
		filePtr = getDataSize() + position;
		break;
	}
	return filePtr < (int)getDataSize();
}

int ADR_CALL Sound::tell()
{
	return filePtr;
}


/**
 * Laduje zasob.
 */
bool Sound::load()
{
	sound = audiere::OpenSound(Game::getSoundManager()->getAudiereDevice(), this, true);
	return (sound != NULL);
}

/**
 * ...
 */
void Sound::unload()
{
	sound = NULL;
}
